/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.hagopa.games.moneypool.dblayer;


import org.hagopa.games.moneypool.utils.ICustLogger;
import org.hagopa.games.moneypool.utils.LogRecord;


import java.sql.SQLException;
import java.sql.Statement;

import org.hagopa.games.moneypool.dblayer.Connector.DBConnector;
/**
 *
 * @author Igor
 */
public class DBCustomLogger implements ICustLogger{
    private String dbquery = "";

    public DBCustomLogger()
    {
        System.out.println ("[DBCustomLogger] Created");
        
    }
    public boolean sendLogMsg(LogRecord newRecord)
    {
       
        Statement stmt = null;
        int count = 0;
        this.dbquery = "INSERT INTO game_log (`user_id` ,`log_msg` ,`game_id`) VALUES(" + newRecord.getClientId() + ", '" + newRecord.getMsg() + "', " + newRecord.getGameId() + ")";
        System.out.println ("QUERY:" + this.dbquery);
        try{
            stmt = DBConnector.getConn().createStatement();

            count = stmt.executeUpdate(dbquery);
            System.out.println ("[DBCustomLogger](sendLogMsg) Insert result:" + count);
            stmt.close();

        } catch (SQLException e) {
                    // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
